//
//  WBHomeViewController.swift
//  小贝微博
//
//  Created by 汪波 on 2017/4/12.
//  Copyright © 2017年 Kevin. All rights reserved.
//

import UIKit
//定义全局常量,尽量使用private修饰,否则到处都可以访问
private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {

    //微博数据数组
    fileprivate lazy var statusList = [String]()
    
    ///加载数据
    override func loadData() {
        for i in 0..<15 {
            //将数据插入到数组的顶部
            statusList.insert(i.description, at: 0)
        }
    }
    /// 显示好友
    @objc fileprivate func showFriends(){
        print(#function)
        let vc = WBDemoViewController()
        //下面的隐藏式存在问题的,每次都要现写,容易忘
        //vc.hidesBottomBarWhenPushed = true
        
        //push的动作是nav做的,可以重写pushViewController这个方法
        navigationController?.pushViewController(vc, animated: true)
        //注意push的时候要隐藏下面的导航栏
        
    }
}

// MARK: - 表格数据源方法,具体的数据源方法实现,不需要super
extension WBHomeViewController {
    //基类已经实现了,所以要加override
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1.取cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //2.设置cell
        cell.textLabel?.text = statusList[indexPath.row]
        //3.返回cell
        return cell
    }
}
// MARK: - 设置界面
extension WBHomeViewController {
    //重写父类的方法
    override func setupUI() {
        super.setupUI()
        //设置导航栏按钮
        //这种无法高亮
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(showFriends))
        
        //自定义,就可以高亮,我们可以搞个按钮,就可以高亮
        //Swift调用OC返回instancetype的方法,判断不出是否可选
//        let btn: UIButton = UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
//        
//        btn.addTarget(self, action: #selector(showFriends), for: .touchUpInside)
//        
//        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", fontSize: 16, target: self, action: #selector(showFriends))
        //注册原型cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
